module EcasesHelper
  
  def format_event_date(date_, unit_)
    year = date_.year.to_s
    month = date_.month.to_s
    day = date_.day.to_s
    hour = date_.hour.to_s
    
    case unit_.id
      when 2: Date::MONTHNAMES[month.to_i] + " " + day.rjust(2,"0") + " " + year.rjust(4,"0")
      when 3: Date::MONTHNAMES[month.to_i] + " " + year.rjust(4,"0")
      when 4: year.rjust(4,"0")
    end
  end

  def get_event_select_block(date_, unit_)
    case unit_.id
      when 2: Proc.new {|i| (date = i.date_time).year == date_.year && date.month == date_.month && date.day == date_.day}
      when 3: Proc.new {|i| (date = i.date_time).year == date_.year && date.month == date_.month}
      when 4: Proc.new {|i| (date = i.date_time).year == date_.year}
    end
  end

  def get_event_date_map_block(unit_)
    case unit_.id
      when 2: Proc.new {|i| DateTime.civil((date = i.date_time).year, date.month, date.day)}
      when 3: Proc.new {|i| DateTime.civil((date = i.date_time).year, date.month,1)}
      when 4: Proc.new {|i| DateTime.civil((date = i.date_time).year,1,1)}
    end
  end
end